package 开始的剑指offer8月.面经常用算法题09开始的;
// https://leetcode-cn.com/problems/find-the-student-that-will-replace-the-chalk/
public class 中等1894找到需要补充粉笔的学生编号0910 {

        public static int chalkReplacer(int[] chalk, int k) {
            int n = chalk.length;
            long total = 0;
            for (int num : chalk) {
                total += num;
            }
            k %= total;
            int res = -1;
            for (int i = 0; i < n; ++i) {
                if (chalk[i] > k) {
                    res = i;
                    break;
                }
                k -= chalk[i];
            }
            return res;
        }

    public static void main(String[] args) {
        System.out.println(chalkReplacer(new int[]{5,1,3},15));
    }

}
